//
//  AFAPIClient.m
//  Edusoho
//
//  Created by Edusoho on 14-6-25.
//  Copyright (c) 2014年 Kuozhi Network Technology. All rights reserved.
//

#import "AFAPIClient.h"

@implementation AFAPIClient

static dispatch_once_t onceToken;

+ (instancetype)sharedClient
{
    static AFAPIClient *_sharedClient = nil;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[AFAPIClient alloc] initWithBaseURL:[NSURL URLWithString:AFAPIBaseURLString]];
        _sharedClient.responseSerializer = [AFCompoundResponseSerializer serializer];
        _sharedClient.requestSerializer.timeoutInterval = 10;
    });
    
    return _sharedClient;
}

+ (void)resetSharedClient
{
    onceToken = 0;
}

- (instancetype)addHeader:(NSString *)headerData forField:(NSString *)fieldString
{
    [self.requestSerializer setValue:headerData forHTTPHeaderField:fieldString];
    return self;
}

- (BOOL)isNetworkReachable
{
    AFNetworkReachabilityManager *reach = [AFNetworkReachabilityManager sharedManager];
    [reach startMonitoring];
    return [reach isReachable];
}

@end
